﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OverStore.Runtime.ObjectRepository.ErrorTransformer
{
    /// <summary>
    /// <para>
    /// Catches exceptions thrown by data storage during persisting (reloading, saving and deleting)
    /// instance of <typeparamref name="TInstance"/> type and then rethrows 
    /// <see cref="OverStore.Runtime.PersistingRuntimeException"/> with pre-configured message.</para>
    /// </summary>
    /// <remarks>
    /// Use properly-configured <see cref="IErrorTransformer{TInstance}"/> object to provide 
    /// human-readable 
    /// </remarks>
    public interface IErrorTransformer<TInstance> : IRuntimeComponent
        where TInstance : class
    {
        /// <summary>
        /// <para>
        /// Analyses specified exception attributes, such as type, message, inner exceptions etc. and
        /// rethrows new <see cref="OverStore.Runtime.PersistingRuntimeException"/> with different message.
        /// </para>
        /// <para>
        /// If specified exception can't be processed, method should do nothing, and calling code 
        /// must rethrow catched exception using <c>throw;</c> statement.
        /// </para>
        /// </summary>
        /// <param name="ex">Exception to analyze.</param>
        /// <exception cref="ArgumentNullException"><paramref name="ex"/> is null reference.</exception>
        /// <exception cref="OverStore.Runtime.PersistingRuntimeException">Argument exception is successfuly analyzed and rethrown.</exception>
        void Transform(PersistingRuntimeException ex);
    }
}
